package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "品牌数据接口测试")
@RestController // @ReponseBody + @Controller
@RequestMapping("admin/product/baseTrademark")
public class TradeMarkController {
    @Autowired
    private BaseTrademarkService baseTrademarkService;

    //http://api.gmall.com/admin/product/baseTrademark/{page}/{limit}
    @GetMapping("{page}/{limit}")
    public Result<IPage<BaseTrademark>> getPage(@PathVariable Long page, @PathVariable Long limit) {
        Page<BaseTrademark> page1 = new Page<>(page, limit);
        IPage<BaseTrademark> pages = baseTrademarkService.getPage(page1);
        return Result.ok(pages);
    }

   //http://api.gmall.com/admin/product/baseTrademark/save
   @PostMapping("save")
   public Result saveTrademark(@RequestBody BaseTrademark baseTrademark) {
        System.out.println(baseTrademark);
       baseTrademarkService.save(baseTrademark);
       return Result.ok();
   }
    //http://api.gmall.com/admin/product/baseTrademark/remove/{id}
    @DeleteMapping("remove/{id}")
    public Result deleteTrademark(@PathVariable Long id) {
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    //http://api.gmall.com/admin/product/baseTrademark/update
    @PutMapping("update")
    public Result deleteTrademark(@RequestBody BaseTrademark baseTrademark) {
        //判断?
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }
    //http://api.gmall.com/admin/product/baseTrademark/get/{id}
    @GetMapping("get/{id}")
    public Result getTrademark(@PathVariable Long id) {
        //判断?
        BaseTrademark byId = baseTrademarkService.getById(id);
        return Result.ok(byId);
    }

    //http://localhost/admin/product/baseTrademark/getTrademarkList
    //新增spu时候用的,品牌从这里选,要用
    @GetMapping("getTrademarkList")
    public Result getTrademark() {
        return Result.ok(baseTrademarkService.getList());
    }
}
